package com.smartHire.controller;

import com.smartHire.util.*;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "testServlet", value = "/testServlet")
public class testServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String code = request.getParameter("code");
        String url="https://api.weixin.qq.com/sns/jscode2session?appid=wx9b8073bb4fe1f8f4&secret=8a99c7e953dc44c7d80cfdef824c7623&js_code=" +
                code+"&grant_type=authorization_code";
        String appid = "wx9b8073bb4fe1f8f4&secret";
        String secret = "8a99c7e953dc44c7d80cfdef824c7623";
        String js_code = code;
        String grant_type = "authorization_code";

        String params = "appid=" + appid + "&secret=" + secret + "&js_code=" + code + "&grant_type=" + grant_type;
        //发送请求
        String sr = HttpRequest.sendGet("https://api.weixin.qq.com/sns/jscode2session", params);
        //解析相应内容（转换成json对象）
        JSONObject json = JSONObject.parseObject(sr);
        //获取会话密钥（session_key）
        String session_key = json.get("session_key").toString();
        //用户的唯一标识（openid）
        String openid = (String) json.get("openid");
        System.out.println("openid:" + openid);


        response.getWriter().write("aaaaaa");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
